/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.worlds.ui.edge;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JEditorPane;
import javax.swing.SwingUtilities;
import net.worlds.Main;

/**
 *
 * @author Jacob
 */
public class EHTMLFrame extends EStickySwingFrame{
    private JEditorPane editor;
    private URL url;
    public EHTMLFrame(EComponent parent, int width, int height, int left, int right, int top, int bottom, final String url)
    {
        super(parent, width, height, left, right, top, bottom);
        editor = new JEditorPane();
        editor.setEditable(false);
        editor.setContentType("text/html");
        editor.addHyperlinkListener(new WorldsHyperlinkListener(EHTMLFrame.this));
        setComponent(editor);
        try {
            this.url = new URL(url);
        } catch (MalformedURLException ex) {
        }
    }
    @Override
    public void setVisible(boolean v)
    {
        super.setVisible(v);
        if(v)
            SwingUtilities.invokeLater(new Runnable()
            {
                public void run() {
                try {
                    editor.setPage(getClass().getResource("/loading.html"));
                    editor.setPage(url);
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
                }
            });
    }
    public void navigate(final URL url)
    {
        SwingUtilities.invokeLater(new Runnable()
        {
            public void run() {
                try {
                    EHTMLFrame.this.url = url;
                    editor.setPage(url);
                    editor.setSize(getWidth() - 10, getHeight() - 10);
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        });

    }
}
